package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.ProblemRelateBean;
import com.renwei.yunlong.utils.StringUtils;
import com.zyf.fwms.commonlibrary.base.baseadapter.BaseRecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 工单信息  相关 --adapter
 * <p>
 * Created by Administrator on 2017/9/6.
 */

public class ProblemRelateAdapter extends BaseRecyclerViewAdapter<ProblemRelateBean.RowsBean> {

    public ProblemRelateAdapter(Context context) {
        super(context);
    }

    @Override
    public WorkRelateViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_work_relate, parent,false);
        return new WorkRelateViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rholder, final int position) {

        WorkRelateViewHolder holder = (WorkRelateViewHolder) rholder;

        final ProblemRelateBean.RowsBean rows = mList.get(position);

        holder.tvLeader.setVisibility(View.GONE);

        holder.tvTitleContent.setText(StringUtils.value(rows.getContent()));
//        String contentName = StringUtils.value(rows.getCompanyName()) + " / " + StringUtils.value(rows.getSendUserName());
        holder.tvName.setText(StringUtils.value(rows.getApplyUserName()));
        holder.tvTime.setText(rows.getQuestionDate());

        if ("4".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);

            holder.button.setText("待申领");
        } else if ("1".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e9981f);
            holder.button.setText("处理中");
        } else if ("2".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("待确认");
        } else if ("3".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("未解决");
        } else if ("6".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("已解决");
        } else if ("-6".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_e64545);
            holder.button.setText("审核未通过");
        } else if ("7".equals(rows.getEventState())) {
            holder.button.setBackgroundResource(R.drawable.shape_card_999691);
            holder.button.setText("已关闭");
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickLitener!=null){
                    mOnItemClickLitener.onItemClick(view,position);
                }
            }
        });
    }


    class WorkRelateViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tv_title_content)
        TextView tvTitleContent;
        @Bind(R.id.button)
        TextView button;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_leader)
        TextView tvLeader;


        public WorkRelateViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
